package org.jypj.dev.util;

import org.jypj.dev.vo.UserWorkFileVo;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by chenyuyuyu on 2017/5/5.
 */
public class RoadFileUtil {


    private static String filePath = PropertyUtil.getProperties("file_path");
    // 总的票数，这个是共享资源，多个线程都会访问


    /**
     * 下载一个交路的所有文件
     */
    public static void downloadFiles(String roadName, List<UserWorkFileVo> userWorkFileVos) {
        try {
            for (UserWorkFileVo userWorkFileVo : userWorkFileVos) {
                StringBuffer sbLocalPath = new StringBuffer(filePath);
                sbLocalPath.append("/" + roadName);
                sbLocalPath.append("/" + userWorkFileVo.getUserNum() + "-" + userWorkFileVo.getUserName());
                sbLocalPath.append("/" + userWorkFileVo.getTrainCode());
                if (StringUtil.isNotEmpty(userWorkFileVo.getParentName())) {
                    sbLocalPath.append("/" + userWorkFileVo.getParentName());
                }
                String workName = userWorkFileVo.getWorkName();
                if (workName.contains("|")) {
                    workName = workName.replace("|", "");
                }
                PathUtil.Path_Judge_Exist(sbLocalPath.toString());
                ImageUtil.customBufferStreamCopy(filePath + userWorkFileVo.getFilePath(), sbLocalPath + "/" + workName + "." + userWorkFileVo.getFileType());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
